package com.example.springboot2.Service;

import com.example.springboot2.DB_Helper.JDBCUtils;
import com.example.springboot2.Model.*;

import java.sql.*;
import java.util.List;

public class QS_CauseService {
    public List<CauseModel>  GetList() {
        Connection conn = JDBCUtils.findConnection();      //JDBCUtils 自己定义的一个类
        PreparedStatement pre = null;
        ResultSet res = null;
        String sql = "select * from QS_Cause_FromMESNext";
        try {
            pre = conn.prepareStatement(sql);
            res = pre.executeQuery();
            //调用将结果集转换成实体对象方法
            List<CauseModel> list = JDBCUtils.Populate(res,CauseModel.class);  //.populate(res, TestModel.class);
            //循环遍历结果
            for(int i=0;i<list.size();i++){
                CauseModel causeModel = (CauseModel) list.get(i);
            }
            return  list;

        } catch (SQLException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }
}
